package com.sailfish.springbootdemo.dao.db7;

import com.sailfish.springbootdemo.common.DB7TableName;
import com.sailfish.springbootdemo.pojo.db7.TbFlowDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface TbFlowDetailDao {

    @Select("<script> " +
            "select \n" +
            "*" +
            " from " + DB7TableName.TB_FLOW_DETAIL +
            " where 1=1 " +
            "<if test='flow_type != null and flow_type!=\"\"'>" +
            " and flow_type = #{flow_type}" +
            "</if>" +
            " order by flow_type asc,flow_level asc,sort asc" +
            "</script>")
    List<TbFlowDetail> getFolwListByType(@Param("flow_type") String flow_type);

    @Select("<script> " +
            "select \n" +
            "*" +
            " from " + DB7TableName.TB_FLOW_DETAIL +
            " where 1=1 " +
            "<if test='flow_type != null and flow_type!=\"\"'>" +
            " and flow_type = #{flow_type}" +
            "</if>" +
            "<if test='flow_level != null and flow_level!=\"\"'>" +
            " and flow_level = #{flow_level}" +
            "</if>" +
            " order by flow_type asc,flow_level asc,sort asc" +
            "</script>")
    List<TbFlowDetail> getFolwListByType3(@Param("flow_type") String flow_type,
                                          @Param("flow_level") Integer flow_level);

    @Select("<script> " +
            "select \n" +
            "*" +
            " from " + DB7TableName.TB_FLOW_DETAIL +
            " where 1=1 " +
            " and flow_type in " +
            "<foreach item='type' index='index' collection='types' open='(' separator=',' close=')'>" +
            "#{type}" +
            "</foreach>" +
            " order by flow_type asc,flow_level asc,sort asc" +
            "</script>")
    List<TbFlowDetail> getFolwListByType2(@Param("types") List<String> flow_type);

    @Insert("<script> " +
            "insert into " + DB7TableName.TB_FLOW_DETAIL +
            " (" +
            "flow_type," +
            "flow_name," +
            "flow_level," +
            "flow_approver," +
            "sort," +
            "create_time," +
            "create_user," +
            "remark" +
            ") " +
            "values " +
            "(" +
            "#{flow_type}," +
            "#{flow_name}," +
            "#{flow_level}," +
            "#{flow_approver}," +
            "#{sort}," +
            "#{create_time}," +
            "#{create_user}," +
            "#{remark}" +
            ")" +
            "</script>")
    Integer insertFlow(TbFlowDetail tbFlow);


    @Update("<script> " +
            "update " + DB7TableName.TB_FLOW_DETAIL +
            " set " +
            "<if test='flow_name != null'>flow_name = #{flow_name},</if>" +
            "<if test='flow_level != null'>flow_level = #{flow_level},</if>" +
            "<if test='flow_approver != null'>flow_approver = #{flow_approver},</if>" +
            "<if test='sort != null'>sort = #{sort},</if>" +
            "<if test='remark != null'>remark = #{remark},</if>" +
            "update_user = #{update_user}," +
            "update_time = #{update_time}" +
            "where id = #{id}" +
            "</script>")
    Integer updateFlow(TbFlowDetail tbFlow);

    @Delete("<script> " +
            "delete from " + DB7TableName.TB_FLOW_DETAIL +
            " where id = #{id}" +
            "</script>")
    Integer deleteFlowById(Integer id);

    @Select("<script> " +
            "select \n" +
            "*" +
            " from " + DB7TableName.TB_FLOW_DETAIL +
            " where id = #{id}" +
            "</script>")
    TbFlowDetail getFlowDetailById(Integer id);

}
